<template>
<div class="icons">
   <swiper :options="swiperOption">
    <swiper-slide v-for="(page, index) of pages" :key="index"> <!--按照数组项来循环，然后展示 -->
        <div class="icon" v-for="item of page" :key="item.id">
          <a :href="item.toUrl">
          <div class="icon-img">
            <img class="icon-img-content" :src='item.imgUrl' />
          </div>
          <p class="icon-desc">{{item.desc}}</p>
          </a>
        </div>
      </swiper-slide>
  </swiper>
</div>
</template>
<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        autoplay: false
      }
    }
  },
  computed:{
    pages () {
      const pages = []  //页面处理 如果图标大于9个是可以转换到下一页
      this.list.forEach((item,index) => { // 遍历 iconList 数组来进行判断
        const page = Math.floor(index / 8)  // 向下取整 大于8 取 1 显示第二个页面的第一项
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)  // 把数据项推到pages里面
      })
      return pages
    }
  }
}
</script>
<style lang="stylus" scoped>
  @import '~styles/varibles.styl';//引用全局文件
  @import '~styles/mixins.styl';  
  .icons >>> .swiper-container
    height 0
    padding-bottom 50%  //屏幕占比度
  .icons
    margin-top .1rem
    .icon
      position relative
      overflow hidden
      height 0
      width 25%
      float left
      padding-bottom 25%
      .icon-img
        position absolute
        left 0
        top 0
        right 0
        bottom .44rem
        box-sizing border-box
        padding .1rem
        .icon-img-content
          height 100%
          display block
          margin 0 auto
      .icon-desc
        position absolute
        left 0
        right 0
        bottom 0
        line-height .44rem
        height .44rem
        color $darkTextColor
        text-align center
        ellipsis() // 解决desc文字特别长的时候，会在后面缩写 
</style>
